package cn.zyq.demo.system.common;

import cn.zyq.demo.beans.sys.SysAdmin;
import cn.zyq.demo.beans.user.User;
import cn.zyq.demo.system.ry.model.LoginUser;
import cn.zyq.demo.service.user.UserService;
import cn.zyq.demo.system.ry.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseController {
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    protected HttpServletResponse response;

    @Autowired
    private UserService userService;

    protected SysAdmin getLoginSysAdmin() {
        return SecurityUtils.getLoginUser().getSysAdmin();
    }

    protected User getLoginUser() {
        return this.userService.getLoginUser();
    }


    /**
     * 获取用户缓存信息
     */
    public LoginUser getMgtLoginUser()
    {
        return SecurityUtils.getLoginUser();
    }

    /**
     * 获取登录用户id
     */
    public Integer getSysAdminID()
    {
        return getMgtLoginUser().getSysAdminID();
    }

    /**
     * 获取登录部门id
     */
    public Integer getDeptId()
    {
        return getMgtLoginUser().getDeptId();
    }

    /**
     * 获取登录用户名
     */
    public String getUsername()
    {
        return getMgtLoginUser().getUsername();
    }
}
